////////////////////////////////////////////////
// File: MeminfoController.java
// Description: Enter summary here after generation.
// Date: 2016-09-23 09:09:34
// Web: http://www.elanzhou.com/
////////////////////////////////////////////////
package com.mvc.controller;
import java.io.IOException;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;


//import com.mvc.entity.User;
//import com.mvc.entity.UserDetail;
import com.mvc.entity.Meminfo;
import com.mvc.service.DictService;
import com.mvc.service.MeminfoService;
import com.pub.MyJson;
import com.pub.Page;
import com.aspose.cells.Cells;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
@Controller
@RequestMapping("BankMeminfo")
public class BankMeminfoController {
	protected final transient Log logger = LogFactory.getLog(BankMeminfoController.class);
	@Autowired
	private MeminfoService meminfoService;
	@Autowired
	private DictService dictService;
	public BankMeminfoController() {
	}

	/* 修改密码 */
	@RequestMapping("Passwd.do")
	public String Passwd(ModelMap modelMap,HttpSession session) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		return "/BankMeminfo/Passwd";
	}
	
	@RequestMapping("ChangePasswd.do")
	public void ChangePasswd(HttpSession session, HttpServletResponse response,
			HttpServletRequest request,ModelMap modelMap) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		String str = "";
		String ID = request.getParameter("ID");
		String oldPasswd = request.getParameter("oldPasswd");
		String newPasswd = request.getParameter("newPasswd");
		String Passwd = request.getParameter("Passwd");
		Meminfo user = (Meminfo) meminfoService.getMeminfo(ID);
		if ((oldPasswd != null) && (oldPasswd.equals(user.getMempass()))) {
			if (newPasswd.equals(Passwd)) {
				str = "{\"statusCode\":200,\"message\":\""
						+ "密码修改成功\",\"callbackType\":\"forward\",\"forwardUrl\":\"/BankMeminfo/Passwd.do\"}";
				user.setMempass(request.getParameter("Passwd"));
				meminfoService.EditSave(user);
				session.setAttribute("SessionUser", user);
			} else {
				str = "{\"statusCode\":300,\"message\":\""
						+ "两次新密码不一致，密码修改失败\",\"callbackType\":\"forward\",\"forwardUrl\":\"\"}";
			}
		} else {
			str = "{\"statusCode\":300,\"message\":\""
					+ "旧密码不匹配，密码修改失败\",\"callbackType\":\"forward\",\"forwardUrl\":\"\"}";
		}
		try {
			response.getWriter().print(str);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	/*编辑*/
	@RequestMapping("Edit.do")
	public String Edit(HttpSession session,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		String id= Integer.toString(smeminfo.getId()) ;
		List hylist=dictService.getAllByKeyname("角色");		
		modelMap.put("hylist",hylist); 			
		Meminfo meminfo=(Meminfo)meminfoService.getMeminfo(id);
		modelMap.put("meminfo", meminfo);
		return "/BankMeminfo/Edit";
	}
    
    /*编辑保存*/
	@RequestMapping("EditSave.do")
	public void EditSave(HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap,HttpSession session) {
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		try {
			String Id=(String)request.getParameter("ID");
			Meminfo  meminfo=(Meminfo)meminfoService.getMeminfo(Id);
			boolean tag=true;
		    String Msg="信息修改成功";
             
            if(tag){
               
               String FieldMemname=(String)request.getParameter("Memname");
             
               if(((FieldMemname!=null)&(!FieldMemname.trim().equals("")))){
            	   FieldMemname=FieldMemname.trim();
                    meminfo.setMemname(FieldMemname);
                  
        		}else
        		{
        			tag=false;
        			Msg="会员名称不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldMempass=(String)request.getParameter("Mempass");
             
               if(((FieldMempass!=null)&(!FieldMempass.trim().equals("")))){
            	   FieldMempass=FieldMempass.trim();
                    meminfo.setMempass(FieldMempass);
                  
        		}else
        		{
        			tag=false;
        			Msg="会员密码不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldRolename=(String)request.getParameter("Rolename");
             
               if(((FieldRolename!=null)&(!FieldRolename.trim().equals("")))){
            	   FieldRolename=FieldRolename.trim();
                    meminfo.setRolename(FieldRolename);
                  
        		}else
        		{
        			tag=false;
        			Msg="角色名称不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldCompanyname=(String)request.getParameter("Companyname");
             
               if(((FieldCompanyname!=null)&(!FieldCompanyname.trim().equals("")))){
            	   FieldCompanyname=FieldCompanyname.trim();
                    meminfo.setCompanyname(FieldCompanyname);
                  
        		}else
        		{
        			tag=false;
        			Msg="公司名称不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldPrivince=(String)request.getParameter("Privince");
             
               if(((FieldPrivince!=null)&(!FieldPrivince.trim().equals("")))){
            	   FieldPrivince=FieldPrivince.trim();
                    meminfo.setPrivince(FieldPrivince);
                  
        		}else
        		{
        			tag=false;
        			Msg="所在省份不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldCity=(String)request.getParameter("City");
             
               if(((FieldCity!=null)&(!FieldCity.trim().equals("")))){
            	   FieldCity=FieldCity.trim();
                    meminfo.setCity(FieldCity);
                  
        		}else
        		{
        			tag=false;
        			Msg="所在市州不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldDistrict=(String)request.getParameter("District");
             
               if(((FieldDistrict!=null)&(!FieldDistrict.trim().equals("")))){
            	   FieldDistrict=FieldDistrict.trim();
                    meminfo.setDistrict(FieldDistrict);
                  
        		}else
        		{
        			tag=false;
        			Msg="所在县区不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldContactman=(String)request.getParameter("Contactman");
             
               if(((FieldContactman!=null)&(!FieldContactman.trim().equals("")))){
            	   FieldContactman=FieldContactman.trim();
                    meminfo.setContactman(FieldContactman);
                  
        		}else
        		{
        			tag=false;
        			Msg="联系人不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldContacttel=(String)request.getParameter("Contacttel");
             
               if(((FieldContacttel!=null)&(!FieldContacttel.trim().equals("")))){
            	   FieldContacttel=FieldContacttel.trim();
                    meminfo.setContacttel(FieldContacttel);
                  
        		}else
        		{
        			tag=false;
        			Msg="联系电话不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldEmail=(String)request.getParameter("Email");
             
               if(((FieldEmail!=null)&(!FieldEmail.trim().equals("")))){
            	   FieldEmail=FieldEmail.trim();
                    meminfo.setEmail(FieldEmail);
                  
        		}else
        		{
        			tag=false;
        			Msg="电子邮箱不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldAddress=(String)request.getParameter("Address");
             
               if(((FieldAddress!=null)&(!FieldAddress.trim().equals("")))){
            	   FieldAddress=FieldAddress.trim();
                    meminfo.setAddress(FieldAddress);
                  
        		}else
        		{
        			tag=false;
        			Msg="地址不能为空！";
        		}
        		}
	         
             
            if(tag){
               
               String FieldRemark=(String)request.getParameter("Remark");
             
               if(((FieldRemark!=null)&(!FieldRemark.trim().equals("")))){
            	   FieldRemark=FieldRemark.trim();
                    meminfo.setRemark(FieldRemark);
                  
        		}else
        		{
        			tag=false;
        			Msg="备注不能为空！";
        		}
        		}
	         
            
            MyJson mj=new MyJson();
              if(tag){
                     meminfoService.EditSave(meminfo);	 
        			 mj.setStatusCode(200);
        		 }else
        		 {
        			 mj.setStatusCode(300);
        		 }
             mj.setMessage(Msg);
             mj.setForwardUrl("/BankMeminfo/Detail.do");
             mj.setCallbackType("forward");
             String str=mj.getJson();
			 response.getWriter().print(str);
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
	} 
    

          	/*编辑*/
	@RequestMapping("Detail.do")
	public String Detail(HttpSession session,ModelMap modelMap)
	{
		Meminfo smeminfo=(Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo",smeminfo);
		
		String id= Integer.toString(smeminfo.getId()) ;	
		Meminfo meminfo=(Meminfo)meminfoService.getMeminfo(id);
		modelMap.put("meminfo", meminfo);
		return "/BankMeminfo/Detail";
	}
    
 
}
